# -*- coding: utf-8 -*-
"""
Created on 2021-09-26 08:48:25
---------
@summary:
---------
@author: Admin
"""

import feapder
from icecream import ic
from items import spider_data_item


class Qs(feapder.AirSpider):
    def start_requests(self):
        for i in range(1,5):
            yield feapder.Request("https://www.qiushibaike.com/8hr/page/{}/".format(i))

    def parse(self, request, response):
        a_list = response.xpath('//a[@class="recmd-content"]')
        for i in a_list:
            title = i.xpath('./text()').extract_first()
            url = i.xpath('./@href').extract_first()
            yield feapder.Request(url,callback = self.parse_detail,xl=title)

    def parse_detail(self,request,response):
        # url = request.url
        content = response.xpath('//div[@class="content"]/text()').extract_first()
        title = request.xl
        ic(title)
        item = spider_data_item.SpiderDataItem()
        item.title = title
        yield item


if __name__ == "__main__":
    Qs(thread_count = 5).start()